package ma.projet.managedbean;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedProperty;

import ma.projet.beans.Service;
import ma.projet.service.ServiceService;

import org.hibernate.HibernateException;

public class ServiceBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Service service;
	private List<Service> services;
	private ServiceService serviceservice;
	@ManagedProperty("#{param.serviceid}")
	private String serviceid;

	public ServiceBean() {
		service = new Service();
		serviceservice = new ServiceService();

	}

	public Service getService() {
		return service;
	}

	public void setService(Service service) {
		this.service = service;
	}

	public List<Service> getServices() throws HibernateException {
		if (services == null)
			try {
				services = serviceservice.load();
				
				
			} catch (HibernateException e) {
				System.out.println("Erreur Liste");
			}
		return services;
	}

	public void setServices(List<Service> services) {
		this.services = services;
	}

	public ServiceService getServiceservice() {
		return serviceservice;
	}

	public void setServiceservice(ServiceService serviceservice) {
		this.serviceservice = serviceservice;
	}

	public String getServiceid() {
		return serviceid;
	}

	public void setServiceid(String serviceid) {

		this.serviceid = serviceid;
		try {
			if (serviceid != null && !serviceid.equals("")) {
				int id = Integer.parseInt(serviceid);
				if (serviceservice != null) {
					this.service = serviceservice.getById(id);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
